<!DOCTYPE html>
<html lang="zh-CH" >
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="author" content="" />
	
	
	
	<title>Unity3D UGUI中将Text的内容复制到粘贴板 ｜ zansimple</title>
	
    
    
    <meta name="description" content="首先要考虑不同的平台之间的差别 pc 端最简单，移动端需要交互，掉用自己的 copy 方法 先写一段代码 pc 端的
using UnityEngine;using System.Collections;using UnityEngine.UI;using UnityEngine.EventSystems;using System;public class CopyText : MonoBehaviour ,IPointerClickHandler{public Text messageText;//创建出来的消息显示的textpublic void OnPointerClick(PointerEventData eventData){TextEditor te = new TextEditor();te.text = messageText.text;te.OnFocus();te.Copy();}} 将脚本放到 Text 物体上就可以了，随后会更新移动端的剪切方式，有什么不懂得地方可以留言。" />
    

    

	
    
    <link rel="shortcut icon" href="https://lenzan.github.io/images/favicon.ico" />

    <link rel="stylesheet" type="text/css" media="screen" href="https://lenzan.github.io/css/normalize.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://cdn.jsdelivr.net/npm/animate.css@4.1.0/animate.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://lenzan.github.io/css/zozo.css" />
	<link rel="stylesheet" type="text/css" media="screen" href="https://cdn.jsdelivr.net/npm/remixicon@2.5.0/fonts/remixicon.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://lenzan.github.io/css/highlight.css" />

    
    
</head>

<body>
    <div class="main animate__animated animate__fadeInDown">
        <div class="nav_container animated fadeInDown">
    <div class="site_nav" id="site_nav">
        <ul>
            
            <li>
                <a href="/">首页</a>
            </li>
            
            <li>
                <a href="/">unity</a>
            </li>
            
            <li>
                <a href="/">归档</a>
            </li>
            
            <li>
                <a href="/">关于</a>
            </li>
            
        </ul>
    </div>
    <div class="menu_icon">
        <a id="menu_icon"><i class="ri-menu-line"></i></a>
    </div>
</div>
        <div class="header animated fadeInDown">
    <div class="site_title_container">
        <div class="site_title">
            <h1>
                <a href="https://lenzan.github.io/">
                    <span>zansimple</span>
                    <img src="https://lenzan.github.io/images/logo.svg" />
                </a>
            </h1>
        </div>
        <div class="description">
            <p class="sub_title">专注于Unity虚拟现实开发，游戏开发</p>
            <div class="my_socials">
                
                <a href="https://lenzan.github.io/index.xml" type="application/rss+xml" title="rss" target="_blank"><i
                        class="ri-rss-fill"></i></a>
            </div>
        </div>
    </div>
</div>
        <div class="content">
            <div class="post_page">
                <div class="post animate__animated animate__fadeInDown">
                    <div class="post_title post_detail_title">
                        <h2><a href='/posts/Unity/Copy/'>Unity3D UGUI中将Text的内容复制到粘贴板</a></h2>
                        <span class="date">2018.05.13</span>
                    </div>
                    <div class="post_content markdown"><!-- raw HTML omitted -->
<p>首先要考虑不同的平台之间的差别 pc 端最简单，移动端需要交互，掉用自己的 copy 方法
先写一段代码 pc 端的</p>
<pre><code>using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;

public class CopyText : MonoBehaviour ,IPointerClickHandler
{
     public Text messageText;//创建出来的消息显示的text
	 
     public void OnPointerClick(PointerEventData eventData)
     {
        TextEditor te = new TextEditor();
        te.text = messageText.text;
        te.OnFocus();
        te.Copy();
     }
	 
}
</code></pre>
<p>将脚本放到 Text 物体上就可以了，随后会更新移动端的剪切方式，有什么不懂得地方可以留言。</p>
</div>
                    <div class="post_footer">
                        
                        <div class="meta">
                            <div class="info">
                                <span class="field tags">
                                    <i class="ri-stack-line"></i>
                                    
                                    <a href="https://lenzan.github.io/tags/Unity3D/">Unity3D</a>
                                    
                                    <a href="https://lenzan.github.io/tags/AssetBundle/">AssetBundle</a>
                                    
                                </span>
                            </div>
                        </div>
                        
                    </div>
                </div>
                
                
            </div>
        </div>
    </div>
    <a id="back_to_top" href="#" class="back_to_top"><span>△</span></a>
    <footer class="footer">
    <div class="powered_by">
        <a href="https://varkai.com">Designed by VarKai,</a>
        <a href="http://www.gohugo.io/">Proudly published with Hugo</a>
    </div>

    <div class="footer_slogan">
        <span></span>
    </div>
</footer>
    <script src="https://lenzan.github.io/js/jquery-3.5.1.min.js"></script>
<link href="https://lenzan.github.io/css/fancybox.min.css" rel="stylesheet">
<script src="https://lenzan.github.io/js/fancybox.min.js"></script>
<script src="https://lenzan.github.io/js/zozo.js"></script>






</body>

</html>